package repositories

import (
    "database/sql"
    "studygo/internal/models"
)

type PersonRepository struct {
    db *sql.DB
}
type PersonRepository struct {
    db *sql.DB
}

func NewPersonRepository(db *sql.DB) *PersonRepository {
    return &PersonRepository{db: db}
}

func (r *PersonRepository) GetUsers() ([]models.Persons, error) {
    rows, err := r.db.Query("select id, name, mobile from member__persons")
    if err != nil {
        return nil, err
    }
    defer rows.Close()

    var users []models.User
    for rows.Next() {
        var u models.User
        if err := rows.Scan(&u.ID, &u.Name, &u.Email); err != nil {
            return nil, err
        }
        users = append(users, u)
    }
    return users, nil
}